<template>
  <el-container class="home-container">
    <!--头部-->
    <el-header>
      <div>
        <el-avatar :size="60" src="https://s3.ax1x.com/2021/02/09/ydXtAS.jpg" 0></el-avatar>
        <span>图书馆后台管理系统</span>
      </div>
      <el-button type="info" @click="outhand">退出</el-button>
    </el-header>
    <el-container>
      <!--侧边栏-->
      <el-aside width="200px">
        <el-menu
          background-color="#373d41"
          text-color="#fff"
          active-text-color="#ffd04b" :unique-opened="true" router
        >
          <el-menu-item index="/welcome">
            <i class="el-icon-menu"></i>
            <span slot="title">主页</span>
          </el-menu-item>
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>图书列表</span>
            </template>
            <!--二级菜单-->
            <el-menu-item :index="item.url" v-for="item in booklist" :key="item.id">
              <i class="el-icon-notebook-1"></i>
              <span>{{item.name}}</span>
            </el-menu-item>
            
          </el-submenu>
        </el-menu>
      </el-aside>
      <!--主体部分-->
      <el-main><router-view/></el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      booklist:[]
    };
  },
  methods: {
    outhand() {
      window.sessionStorage.clear();
      this.$router.push("/Login");
      this.$message.success("退出成功,感谢您的使用！");
    },
    async getbooklist() {
      const {data} = await this.$http.get('bookList/getbooklist')
      if (data.stats !== 200) return this.$message.error('数据获取失败')
       this.booklist = data.rows 
    }
  },
    created() {
    this.getbooklist()
  }
};

</script>

<style lang="less" scoped>
.el-main {
  background-color: rgba(235, 235, 235, 0.904);
}
.home-container {
  height: 100%;
}
.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: #fff;
  font-size: 20px;
  > div {
    display: flex;
    align-items: center;
    span {
      margin-left: 15px;
    }
  }
}
.el-header img {
  height: 50px;
}
.el-aside {
  background-color: #373d41;
}
</style>